<?php 
exit;
set_time_limit(0);

$url = "http://v.juhe.cn/sms/send";


/**
$params = array(
    'key'   => '597d46217e4b498fc2ac0da6a67b68a7', //您申请的APPKEY
    'mobile'    => '15001800051', //接受短信的用户手机号码
    'tpl_id'    => '176236', //您申请的短信模板ID，根据实际情况修改
    'tpl_value' =>'#code#=1234' //您设置的模板变量，根据实际情况修改
);

$paramstring = http_build_query($params);
$content = juheCurl($url, $paramstring);
$result = json_decode($content, true);
if ($result) {
    //var_dump($result);
} else {
    //请求异常
}
*/





function juheCurl($url, $params = false, $ispost = 0)
{
    $httpInfo = array();
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'JuheData');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    if ($ispost) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_URL, $url);
    } else {
        if ($params) {
            curl_setopt($ch, CURLOPT_URL, $url.'?'.$params);
        } else {
            curl_setopt($ch, CURLOPT_URL, $url);
        }
    }
    $response = curl_exec($ch);
    if ($response === FALSE) {
        //echo "cURL Error: " . curl_error($ch);
        return false;
    }
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
    curl_close($ch);
    return $response;
} 



 


require_once  './Classes/PHPExcel.php';

function format_excel2array($filePath='',$sheet=1){
    if(empty($filePath) or !file_exists($filePath)){die('file not exists');}
    $PHPReader = new PHPExcel_Reader_Excel2007();        //建立reader对象
    if(!$PHPReader->canRead($filePath)){
        $PHPReader = new PHPExcel_Reader_Excel5();
        if(!$PHPReader->canRead($filePath)){
            echo 'no Excel';
            return ;
        }
    }
    $PHPExcel = $PHPReader->load($filePath);        //建立excel对象
    $currentSheet = $PHPExcel->getSheet($sheet);        //**读取excel文件中的指定工作表*/
    $allColumn = $currentSheet->getHighestColumn();        //**取得最大的列号*/
    $allRow = $currentSheet->getHighestRow();        //**取得一共有多少行*/
    $data = array();
    for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){        //循环读取每个单元格的内容。注意行从1开始，列从A开始
        for($colIndex='A';$colIndex<=$allColumn;$colIndex++){
            $addr = $colIndex.$rowIndex;
            $cell = $currentSheet->getCell($addr)->getValue();
            if($cell instanceof PHPExcel_RichText){ //富文本转换字符串
                $cell = $cell->__toString();
            }
            $data[$rowIndex][$colIndex] = $cell;
        }
    }
    return $data;
}


$data = format_excel2array('./ctrip.xlsx', 0);
foreach ($data as $k => $v){
    if ($k>1 && !empty($v['E'])){
        $phone=trim($v['E']);
        
        echo $phone;
        
        $params = array(
            'key'   => '597d46217e4b498fc2ac0da6a67b68a7', //您申请的APPKEY
            'mobile'    => $phone, //接受短信的用户手机号码
            'tpl_id'    => '176236', //您申请的短信模板ID，根据实际情况修改
            'tpl_value' =>'#code#=1234' //您设置的模板变量，根据实际情况修改
        );
        
        $paramstring = http_build_query($params);
        $content = juheCurl($url, $paramstring);
        $result = json_decode($content, true);
        if ($result) {
            var_dump($result);
        } else {
            //请求异常
        }
        
        echo "<br /><br />";
    }
}



echo "<br />"; echo "<br />"; echo "<br />";
var_dump($data);